C# ComboBox SelectedItem [closed]
Posted
by
Diane
on Programmers
See other posts from Programmers
or by Diane
Published on 2012-10-10T19:25:58Z
Indexed on
2012/10/10
21:52 UTC
Read the original article
Hit count: 180
c#
I have a combobox with a list of values. I would like the selected index to be a value from the database. I first create the combobox, fill it with values from a dataset like this:
ComboBox cmb_Relay = new ComboBox();
cmb_Relay.DataSource = ds2.Tables[0];
cmb_Relay.DisplayMember = "Relay";
cmb_Relay.ValueMember = "Relay";
Next, I set the SelectedIndex to the value of a specific field value:
cmb_Relay.SelectedItem = ds2.Tables[0].Rows[j][2];
I get the follwing error:
InvalidArgument=Value of '3' is not valid for 'SelectedIndex'. Parameter name: SelectedIndex
© Programmers or respective owner